import createDomElement from './createDomElement';
import unmountNode from './unmountNode';

export default function mountNativeElement(virtualDOM, container, oldDOM) {
    
    let newElement = createDomElement(virtualDOM);

    // 删除旧的DOM对象
    if (oldDOM) {
        unmountNode(oldDOM);
    }

    // 将转换后的DOM对象放置在页面中
    container.appendChild(newElement);
    // 获取类组件实例对象
    let component = virtualDOM.component;

    if (component) {
        // 将DOM对象存储在类组件实例对象中
        component.setDOM(newElement);
    }
};